{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "63907ec7",
   "metadata": {},
   "source": [
    "---\n",
    ">> 变量"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7693f8c8",
   "metadata": {},
   "source": [
    "#  本周知识点\n",
    "> 1.回顾变量的概念  \n",
    "> 2.条件判断  \n",
    "> 3.for循环和range方法  \n",
    "> 4.random模块（伪随机数模块）  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18a3f7a5",
   "metadata": {},
   "source": [
    "## 回顾变量的概念"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "bff9e6de",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新_01_ID = \"21000002\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d9a23e2a",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新_01_Age = \"18\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5b7ad333",
   "metadata": {},
   "source": [
    "### 2.条件判断 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2d8efeda",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15\n",
      "现在是秒/时间为奇数\n"
     ]
    }
   ],
   "source": [
    "import datetime\n",
    "# 本项目用到了时间模块\n",
    "# print(datetime.datetime.today().microsecond)\n",
    "\n",
    "# odds 是一个变量，后面可以直接使用\n",
    "odds = [  1, 3,  5,  7,  9, 11,13,15,17,19,\n",
    "             21,23,25,27,29,31,33,35,37,39,\n",
    "             41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "# right_this_minute 是一个变量，是随着当前时间分钟数不断变化的一个值\n",
    "right_this_minute = datetime.datetime.today().second\n",
    "\n",
    "\n",
    "if right_this_minute in odds:\n",
    "    print(right_this_minute)\n",
    "    print(\"现在是秒/时间为奇数\")\n",
    "else:\n",
    "    print(right_this_minute)\n",
    "    print(\"现在秒/时间为偶数\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a11d97ac",
   "metadata": {},
   "source": [
    "* 判断当前是一周中的星期几，如果是星期二，看下现在几点了，是python课ing么？然后打印Python课表  \n",
    "* 实践，通过if判断 实现课程表打印  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d32e08dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "#help(datetime)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a6a74059",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Work, work, work.\n"
     ]
    }
   ],
   "source": [
    "# 创建today变量(模块获取今天的星期几？)\n",
    "# 知识点： 1. 先创建变量，才能进行判断\n",
    "#          2. if语句 观察条件判断块的位置\n",
    "#          3. 按照条件块的间隙 找到归属关系\n",
    "\n",
    "today = \"Monday\"\n",
    "condition = \"good\"\n",
    "\n",
    "if today == \"Saturday\":\n",
    "    print(\"超开心\")  # if条件判断块\n",
    "elif today == \"Sunday\":\n",
    "    if condition == \"Headache\":\n",
    "        print(\"Recover, then rest.\")\n",
    "    else:\n",
    "        print(\"Rest.\")\n",
    "else:\n",
    "    print(\"Work, work, work.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7235934d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# wkday = 0，1，2，3，4，5，6   分别指周一到周日\n",
    "import time \n",
    "\n",
    "wday  = time.localtime().tm_wday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "460cb34a",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_hour = time.localtime().tm_hour"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2a30a640",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_min = time.localtime().tm_min"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "85fe2329",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "今天没有Python课\n"
     ]
    }
   ],
   "source": [
    "if wday != 1: # 判断是否是周二\n",
    "    print(\"今天没有Python课\")\n",
    "elif time_hour == 12 and time_min > 50:\n",
    "    print(\"正在上Python课,刚上课\")\n",
    "elif time_hour == 13:\n",
    "    print(\"正在上Python课，大概第二节了\")\n",
    "elif time_hour == 14:\n",
    "    print(\"正在上Python课，妈呀，还在上，才2点\")\n",
    "elif time_hour == 15:\n",
    "    print(\"正在上Python课，坚持一下，快下课了！\")\n",
    "elif time_hour == 16 and time_min<50:\n",
    "    print(\"正在上Python课，最后一节课了，块下课啦\")\n",
    "else:\n",
    "    print(\"今天有Python课，上课时间是下午12.50-16.50\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5a143cbf",
   "metadata": {},
   "source": [
    "## 4.for循环和range方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2866b0be",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "# item 循环遍历\n",
    "for item in [1,2,3]:\n",
    "    print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f40ff08a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2100001\n",
      "2100002\n",
      "2100003\n"
     ]
    }
   ],
   "source": [
    "# 自动生成学号\n",
    "for item in [1,2,3]:\n",
    "    print(item+2100000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7b6e7690",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "#  range()自动生成想要的数值，可以控制for循环的次数，一个值，就是从0开始几个数\n",
    "for num in range(5):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "8f7960c8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "# range()自动生成想要的数值，可以控制for循环的次数，两个值，从小数（2）开始，大数-小数的个数（5-2）\n",
    "for num in range(2,5):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "0ee58643",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "3\n",
      "6\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "# 三个值，第三个值决定step步长\n",
    "for num in range(0,10,3):\n",
    "    print(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "9f90d4a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.nfu.edu.cn/ztb/index0.htm\n",
      "https://www.nfu.edu.cn/ztb/index1.htm\n",
      "https://www.nfu.edu.cn/ztb/index2.htm\n",
      "https://www.nfu.edu.cn/ztb/index3.htm\n",
      "https://www.nfu.edu.cn/ztb/index4.htm\n",
      "https://www.nfu.edu.cn/ztb/index5.htm\n",
      "https://www.nfu.edu.cn/ztb/index6.htm\n",
      "https://www.nfu.edu.cn/ztb/index7.htm\n",
      "https://www.nfu.edu.cn/ztb/index8.htm\n",
      "https://www.nfu.edu.cn/ztb/index9.htm\n",
      "https://www.nfu.edu.cn/ztb/index10.htm\n",
      "https://www.nfu.edu.cn/ztb/index11.htm\n",
      "https://www.nfu.edu.cn/ztb/index12.htm\n",
      "https://www.nfu.edu.cn/ztb/index13.htm\n",
      "https://www.nfu.edu.cn/ztb/index14.htm\n",
      "https://www.nfu.edu.cn/ztb/index15.htm\n",
      "https://www.nfu.edu.cn/ztb/index16.htm\n",
      "https://www.nfu.edu.cn/ztb/index17.htm\n",
      "https://www.nfu.edu.cn/ztb/index18.htm\n",
      "https://www.nfu.edu.cn/ztb/index19.htm\n",
      "https://www.nfu.edu.cn/ztb/index20.htm\n",
      "https://www.nfu.edu.cn/ztb/index21.htm\n",
      "https://www.nfu.edu.cn/ztb/index22.htm\n",
      "https://www.nfu.edu.cn/ztb/index23.htm\n",
      "https://www.nfu.edu.cn/ztb/index24.htm\n",
      "https://www.nfu.edu.cn/ztb/index25.htm\n",
      "https://www.nfu.edu.cn/ztb/index26.htm\n"
     ]
    }
   ],
   "source": [
    "# for循环遍历案例 ： 某学校新闻网站数据URL队列获取\n",
    "\n",
    "# 中大南方-招投标- https://www.nfu.edu.cn/ztb/index.htm\n",
    "\n",
    "中大南方_招投标 = \"https://www.nfu.edu.cn/ztb/index.htm\"\n",
    "for page in range(27):\n",
    "    print(\"https://www.nfu.edu.cn/ztb/index\" + str(page) + \".htm\" )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d4966f6",
   "metadata": {},
   "source": [
    "# 5.random模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b1b07cea",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "143a273c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6853494318741548"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# random. random方法：（）\n",
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "945b0009",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.randint(1,50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1cb94787",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
